package demo1;

import java.util.HashMap;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    //何为k的子数组
    public int subarraySum(int[] nums, int k) {
        int count = 0;
        HashMap<Integer,Integer> map = new HashMap<>();
        map.put(0,1);
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum+=nums[i];
            //map.put(sum,map.getOrDefault(sum,0)+1);
            count += map.getOrDefault(sum-k,0);
            map.put(sum,map.getOrDefault(sum,0)+1);
        }
        return count;
    }

    //除自身以外数组的乘积
    public int[] productExceptSelf(int[] nums) {
        int n = nums.length;
        int[] dp1 = new int[n];
        int[] dp2 = new int[n];
        for (int i = 0; i < n; i++) {
            if(i==0) dp1[i] = 1;
            dp1[i] = dp1[i-1] * nums[i-1];
        }
        for (int i = n-1; i >= 0 ; i--) {
            if(i==n-1) dp2[i] = 1;
            dp2[i] = dp2[i+1] * nums[i+1];
        }
        int[] ret = new int[n];
        for (int i = 0; i < n; i++) {
            ret[i] = dp1[i]*dp2[i];
        }
        return ret;
    }

    public static void main1(String[] args) {
        System.out.println(10.0);
    }

    //超级饮料的最大强化能量
    public long maxEnergyBoost(int[] energyDrinkA, int[] energyDrinkB) {
        int n = energyDrinkA.length;
        long[] dpA = new long[n];
        long[] dpB = new long[n];
        for (int i = 0; i < n; i++) {
            if (i == 0) {
                dpA[i] = energyDrinkA[i];
                dpB[i] = energyDrinkB[i];
                continue;
            } else if (i == 1) {
                dpA[i] = energyDrinkA[i]+energyDrinkA[i-1];
                dpB[i] = energyDrinkB[i]+energyDrinkB[i-1];
                continue;
            }
            dpA[i] = Math.max(dpA[i-1],dpB[i-2])+energyDrinkA[i];
            dpB[i] = Math.max(dpB[i-1],dpA[i-2])+energyDrinkB[i];
        }

        return Math.max(dpA[n-1],dpB[n-1]);
    }
}
